#!/usr/bin/env python3
"""
简单的项目结构测试
"""

import os
from pathlib import Path

def test_project_structure():
    """测试项目结构"""
    print("=== 项目结构检查 ===\n")
    
    required_files = [
        "README.md",
        "backend/requirements.txt",
        "backend/app/main.py",
        "backend/app/models/schemas.py",
        "backend/app/services/llm_service.py",
        "backend/app/services/rag_service.py",
        "backend/app/services/arxiv_service.py",
        "frontend/index.html",
        "frontend/css/style.css",
        "frontend/js/app.js",
        "docs/technical_implementation.md",
        "docs/deployment.md",
        "docker-compose.yml",
        "netlify.toml",
        ".gitignore"
    ]
    
    required_dirs = [
        "backend/app",
        "backend/app/models",
        "backend/app/services",
        "backend/app/utils",
        "frontend",
        "frontend/css",
        "frontend/js",
        "docs",
        "scripts"
    ]
    
    print("检查目录结构:")
    dirs_ok = 0
    for dir_path in required_dirs:
        if os.path.exists(dir_path):
            print(f"✓ {dir_path}/")
            dirs_ok += 1
        else:
            print(f"✗ {dir_path}/")
    
    print(f"\n目录检查: {dirs_ok}/{len(required_dirs)} 通过\n")
    
    print("检查关键文件:")
    files_ok = 0
    for file_path in required_files:
        if os.path.exists(file_path):
            size = os.path.getsize(file_path)
            print(f"✓ {file_path} ({size} bytes)")
            files_ok += 1
        else:
            print(f"✗ {file_path}")
    
    print(f"\n文件检查: {files_ok}/{len(required_files)} 通过")
    
    return dirs_ok == len(required_dirs) and files_ok == len(required_files)

def show_project_tree():
    """显示项目目录树"""
    print("\n=== 项目目录树 ===")
    
    def print_tree(directory, prefix="", max_depth=3, current_depth=0):
        if current_depth >= max_depth:
            return
            
        try:
            items = sorted(os.listdir(directory))
            dirs = [item for item in items if os.path.isdir(os.path.join(directory, item)) and not item.startswith('.')]
            files = [item for item in items if os.path.isfile(os.path.join(directory, item)) and not item.startswith('.')]
            
            # 打印目录
            for i, dirname in enumerate(dirs):
                is_last_dir = (i == len(dirs) - 1) and len(files) == 0
                print(f"{prefix}{'└── ' if is_last_dir else '├── '}{dirname}/")
                extension = "    " if is_last_dir else "│   "
                print_tree(os.path.join(directory, dirname), prefix + extension, max_depth, current_depth + 1)
            
            # 打印文件
            for i, filename in enumerate(files):
                is_last = i == len(files) - 1
                print(f"{prefix}{'└── ' if is_last else '├── '}{filename}")
                
        except PermissionError:
            print(f"{prefix}[权限不足]")
    
    print_tree(".")

def main():
    """主函数"""
    print("论文搜索引擎项目检查\n")
    
    # 检查项目结构
    structure_ok = test_project_structure()
    
    # 显示目录树
    show_project_tree()
    
    # 总结
    print("\n=== 检查结果 ===")
    if structure_ok:
        print("🎉 项目结构完整！")
        print("\n下一步操作:")
        print("1. 安装Python依赖: pip install -r backend/requirements.txt")
        print("2. 配置环境变量: 复制 backend/.env.example 为 backend/.env")
        print("3. 启动开发服务器: python scripts/start_dev.py")
        print("4. 访问前端: 打开 frontend/index.html")
    else:
        print("⚠ 项目结构不完整，请检查缺失的文件和目录")
    
    print(f"\n当前工作目录: {os.getcwd()}")

if __name__ == "__main__":
    main()